﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using ThreeByte.ActiveDeck.Config;
using System.Text.RegularExpressions;

namespace ThreeByte.ActiveDeck.AddIn.Controls.Wizard
{
    public class ActivityTypeCounter : INotifyPropertyChanged
    {


        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName) {
            if(PropertyChanged != null) {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }


        private int _mirrorSlides;
        public int MirrorSlides {
            get {
                return _mirrorSlides;
            }
            private set {
                _mirrorSlides = value;
                NotifyPropertyChanged("MirrorSlides");
            }
        }

        private int _audienceResponse;
        public int AudienceResponse {
            get {
                return _audienceResponse;
            }
            private set {
                _audienceResponse = value;
                NotifyPropertyChanged("AudienceResponse");
            }
        }

        private int _photos;
        public int Photos {
            get {
                return _photos;
            }
            private set {
                _photos = value;
                NotifyPropertyChanged("Photos");
            }
        }

        private int _videos;
        public int Videos {
            get {
                return _videos;
            }
            private set {
                _videos = value;
                NotifyPropertyChanged("Videos");
            }
        }


        private CoreConfig _config;

        public ActivityTypeCounter(CoreConfig config) {
            _config = config;
        }

        public void Refresh() {

            //Calculate the numer of slides of each type
            int mirrorCount = 0;
            int questionCount = 0;
            int photoCount = 0;
            int videoCount = 0;
            foreach(SlideConfig s in _config.Slides.OrderBy(p => p.SlideNumber)) {
                foreach(PageConfig p in s.Pages) {
                    if(p is QuestionConfig
                        || p is MultipleChoiceConfig
                        || p is CategoriesConfig) {
                        questionCount++;
                    }
                    if(p is UserSlideConfig
                        && Regex.IsMatch(p.Name, @"Mirror_Slide_\d{3}")) {
                        mirrorCount++;
                    }
                    if(p is UserSlideConfig
                        && Regex.IsMatch(p.Name, @"Photo_")) {
                        photoCount++;
                    }
                    if(p is DesignerSlideConfig
                        && Regex.IsMatch(p.Name, @"Video_")) {
                        videoCount++;
                    }

                }
            }

            MirrorSlides = mirrorCount;
            AudienceResponse = questionCount;
            Photos = photoCount;
            Videos = videoCount;
        }

    }
}
